﻿@model IEnumerable<MVC4Shop.Models.CartModel>
@{
    ViewBag.Title = "Index";
}

<script type="text/jscript">
    $(document).ready(function () {
        $('.delete').click(function () {
            var id = $(this).attr('id');
            $.ajax({
                url: '@Url.Action("Delete", "ShoppingCart")',
                data: JSON.stringify({ product_id: id }),
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (result) {
                    if (result.kq) {
                        $('#row' + id).remove();
                        alert("Đã xóa hàng");
                    }
                },
                error: function () {
                    alert("Không thể xóa hàng");
                }

            });
        });
    });
</script>

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.product_id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.image)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.price)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.detail_id)
        </th>
        <th>
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr id="@item.row()">
            <td>
                @Html.DisplayFor(modelItem => item.product_id)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.image)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.detail_id)
            </td>
            <td>
                <input type="button" class="delete" value="Xóa" id="@item.product_id"/>
            </td>
        </tr>
    }
</table>
